<?
	function writeDateTime($name, $date){
		echo '<select name="'.$name.'" class=inpts>';
		foreach ( $date  as $data ) {
			echo '<option value="';
			echo $data ['VALUE'].'"';
			echo ($data ['SELECTED'] == 1 ? 'selected' : '');
			echo' >';
				echo $data ['NAME'];
			echo '</option>';
		}
	  echo '</select>';
	}

  $frm['gid'] = intval ($frm['gid']);
  $frm['lid'] = intval ($frm['lid']);
  $q = 'select *, date_format(date_added, \'%b %D, %Y\') as fdate_added from hl_listings where status = 2 and id = ' . $frm['lid'];
  if (!($sth = mysql_query ($q))) {
    exit (mysql_error ());
  }

  $row = mysql_fetch_array ($sth);
  if (!$row) {
    print 'Invalid listing id';
    exit ();
  }

  $listing = array ();
  $q = 'select * from hl_groups';
  if (!($gsth = mysql_query ($q))) {
    exit (mysql_error ());
  }

  $listings = array ();
  while ($grow = mysql_fetch_array ($gsth)) {
    if ($grow['id'] == $row['group_id']) {
      $listing = $grow;
    }
    array_push ($listings, $grow);
  }
?>
<form method=post name="approve_form">
	<input type="hidden" name="a" value="approve_listing">
	<input type="hidden" name="action" value="save">
	<input type="hidden" name="lid" value="<?php echo $frm['lid'];?>">
	<input type="hidden" name="gid" value="<?php echo $frm['gid'];?>">
	<input type="hidden" name="p" value="<?php echo $frm['p'];?>">
	<input type="hidden" name="return" value="<?php echo $frm['return'];?> ">
	<table cellspacing=1 cellpadding=2 border=0 width=100%>
		<tr>
 		<td width=30%>Name:</td>
 		<td><input type="text" name="name" value="<?php echo htmlspecialchars ($row['name']);?>" class=inpts size=50></td>
	</tr>
	<tr>
 		<td>Group:</td>
 		<td>
  		<select name="group_id" class=inpts>
  		<?php foreach ($listings as $tgroup) {?>
    		<option value="<?php echo $tgroup['id'];?>" <?php echo ($tgroup['id'] == $row['group_id'] ? 'selected' : '');?> >
    			<?php echo htmlspecialchars ($tgroup['name']);?>
    		</option>
  		<?php }?>

  		</select>
 		</td>
	</tr>
<tr>
 <td>Rating:</td>
 <td>
  	<select name="rating" class=inpts>
  	<?php for ($i = 0; $i <= 5; ++$i) {?>
    	<option value=<?php echo $i;?> <?php echo ($i == $row['rating'] ? 'selected' : '');?> >
    		<?php echo $i;?>
    	</option>
  	<?php }?>
  	</select>
 </td>
</tr>
<tr>
 <td>Status:</td>
  <td>
  	<select name="status" class=inpts>
     <option value=0>Off</option>
     <option value=1 selected>On</option>
     <option value=2>Not Approved</option>
   </select>
  </td>
</tr>
<tr>
 <td>Paying Status:</td>
  <td>
  	<select name="hyip_status" class=inpts>
     <option value=1 <?php echo ($row['hyip_status'] == 1 ? 'selected' : '');?> >Paying</option>
     <option value=2 <?php echo ($row['hyip_status'] == 2 ? 'selected' : '');?> >Waiting</option>
     <option value=3 <?php echo ($row['hyip_status'] == 3 ? 'selected' : '');?> >Problem</option>
     <option value=4 <?php echo ($row['hyip_status'] == 4 ? 'selected' : '');?> >Not Paying</option>
   </select>
  </td>
</tr>
<tr>
 <td>URL:</td>
 <td><input type="text" name="url" value="<?php echo htmlspecialchars ($row['url']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>Percents:</td>
 <td><input type="text" name="percents" value="<?php echo htmlspecialchars ($row['percents']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>Minimal Spend:</td>
 <td><input type="text" name="min_spend" value="<?php echo htmlspecialchars ($row['min_spend']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>Maximal Spend:</td>
 <td><input type="text" name="max_spend" value="<?php echo htmlspecialchars ($row['max_spend']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>Referral:</td>
 <td><input type="text" name="referral" value="<?php echo htmlspecialchars ($row['referral']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>Withdrawal:</td>
 <td>
 		<select name="withdrawal_type" class=inpts>
     <option value=1 <?php echo ($row['withdrawal_type'] == 1 ? 'selected' : '');?> >Manual</option>
     <option value=2 <?php echo ($row['withdrawal_type'] == 2 ? 'selected' : '');?> >Instant</option>
     <option value=3 <?php echo ($row['withdrawal_type'] == 3 ? 'selected' : '');?> >Automatic</option>
   </select>
 </td>
</tr>
<tr>
 <td>Contact E-mail:</td>
 <td><input type="text" name="email" value="<?php echo htmlspecialchars ($row['email']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>Support E-mail:</td>
 <td><input type="text" name="support_email" value="<?php echo htmlspecialchars ($row['support_email']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>TG Support Forum:</td>
 <td><input type="text" name="support_form" value="<?php echo htmlspecialchars ($row['support_form']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>MMG Support Forum:</td>
 <td><input type="text" name="support_forum" value="<?php echo htmlspecialchars ($row['support_forum']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>DTM Support Forum:</td>
 <td><input type="text" name="support_aim" value="<?php echo htmlspecialchars ($row['support_aim']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>Added:</td>
  <?php 
  preg_match ('/(\\d+)-(\\d+)-(\\d+)/', $row['date_added'], $parts);
  $date = get_date_arrays ($parts[1], $parts[2], $parts[3], 10, 10);
  ?>
 <td>
 	<?php 
 			writeDateTime('month', $date['MONTHS']);
 			writeDateTime('day', $date['DAYS']);
 			writeDateTime('year', $date['YEARS']);
 	?>		
 </td>
</tr>
<tr>
 <td>Started:</td>
  <?php 
  preg_match ('/(\\d+)-(\\d+)-(\\d+)/', $row['date_started'], $parts);
  $date = get_date_arrays ($parts[1], $parts[2], $parts[3], 10, 10);
  ?>
 <td>
 	<?php 
 			writeDateTime('smonth', $date['MONTHS']);
 			writeDateTime('sday', $date['DAYS']);
 			writeDateTime('syear', $date['YEARS']);
 	?>		
 </td>
</tr>
<tr>
 <td>Expires After:</td>
 <td>
 	<input type="text" name="expiration" value="<?php echo htmlspecialchars ($row['expiration']);?>" class=inpts size=10> days (enter '0' to skip limitation)
 </td>
</tr>
<tr>
 <td>Closed:</td>
  <?php 
  preg_match ('/(\\d+)-(\\d+)-(\\d+)/', $row['date_closed'], $parts);
  if (($parts[1] != 0 AND $parts[1] - date ('Y') < -5)) {
    $prev_years = date ('Y') - $parts[1] + 5;
  } else {
    $prev_years = 5;
  }
  $date = get_date_arrays ($parts[1], $parts[2], $parts[3], $prev_years, 5);
  ?>
 <td>
 	<select name="cmonth" class=inpts>
   <option value=0>-</option>
   <?php foreach ($date['MONTHS'] as $data) {?>
    <option value="<?php echo $data['VALUE'];?>" <?php echo ($data['SELECTED'] == 1 ? 'selected' : '');?> >
    	<?php echo $data['NAME'];?>
    </option>
  <?php }?>
  </select>
  <select name="cday" class=inpts>
   <option value=0>-</option>
   <?php foreach ($date['DAYS'] as $data) {?>
   <option value="<?php echo $data['VALUE'];?>" <?php echo ($data['SELECTED'] == 1 ? 'selected' : '');?> >
    <?php echo $data['NAME'];?>
   </option>
  <?php }?>
  </select>
  <select name="cyear" class=inpts>
	   <option value=0>-</option>
	   <?php foreach ($date['YEARS'] as $data) {?>
	    <option value="<?php echo $data['VALUE'];?>" <?php echo ($data['SELECTED'] == 1 ? 'selected' : '');?> >
	    	<?php echo $data['NAME'];?>
	    </option>
	   <?php }?>
  </select>
 </td>
</tr>
<tr>
  <td valign=top>Payment Systems:</td>
  <td>
  <?php 
  $payments = preg_split ('/\\s*,\\s*/', $settings['payments']);
  $apayments = preg_split ('/\\s*,\\s*/', $row['pay_systems']);
  foreach ($payments as $payment) {?>
  	<input type="checkbox" name="payments[<?php echo $payment;?>]" value=1 <?php echo (in_array ($payment, $apayments) ? 'checked' : '');?> >
    	<?php echo $payment;?>
    <br>
  <?php }?>
  </td>
</tr>
 <?php 
  $a_accounts = preg_split ('/\\|/', $row['account']);
  $b_accounts = array ();
  for ($i = 0; $i < sizeof ($a_accounts); ++$i)
  {
    if ($a_accounts[$i] == '')
    {
      continue;
    }

    array_push ($b_accounts, $a_accounts[$i]);
  }

  $accounts = join (',', $b_accounts);
 ?> 
 <tr>
 <td>HYIP E-currency Accounts:</td>
 <td><input type="text" name="account" value="<?php echo htmlspecialchars ($accounts);?>" class=inpts size=10></td>
</tr>
<tr>
  <td colspan=2>Default Language Description:</td>
</tr>
<tr>
  <td colspan=2>
  	<textarea name="description" cols=82 rows=5 class=inpts>
  		<?php echo $row['description'];?>
  	</textarea>
  </td>
</tr>
<tr>
	<td>Monitoring Image: </td>
	<?php 
  if (is_file ('./image.php')) {
    $sn = $frm_env['SCRIPT_NAME'];
    $sn = preg_replace ('/admin\\.php/', 'image.php', $sn);
    $sn .= '?lid=' . $row['id'];
  } else {
    $sn = $frm_env['SCRIPT_NAME'];
    $sn = preg_replace ('/admin\\.php/', 'index.php', $sn);
    $sn .= '?a=image&lid=' . $row['id'];
  }
  ?>
  <td><a href="http://<?php echo $frm_env['HTTP_HOST'] . $sn;?>" target=_blank>
  	http://<?php echo $frm_env['HTTP_HOST'] . $sn;?> 
  	</a></td>
</tr>
</table>
 <script>
function chng_status()
{
  var obj = document.approve_form;
  var flag = !obj.send_notification.checked;
  obj.from.disabled = flag;
  obj.to.disabled = flag;
  obj.subject.disabled = flag;
  obj.text.disabled = flag;
}
</script>
<?php 
  $row['withdrawal_type'] = ($row['withdrawal_type'] == 1 ? 'Manual' : ($row['withdrawal_type'] == 2 ? 'Instant' : 'Automatic'));
  $row['group'] = $listing['name'];
  $row['date_added'] = $row['fdate_added'];
  $q = 'select * from hl_emails where id = \'listing_approve\'';
  $sth = mysql_query ($q);
  $email = mysql_fetch_array ($sth);
  $text = $email['text'];
  $subject = $email['subject'];
  reset ($row);
  foreach ($row as $k => $v) {
    if (is_array ($v)) {
      continue;
    }

    $v = strip_tags ($v);
    $v = preg_replace ('' . '/(\\$)/', '\\\\$', $v);
    $text = preg_replace ('' . '/#' . $k . '#/', '' . $v, $text);
    $subject = preg_replace ('' . '/#' . $k . '#/', '' . $v, $subject);
  }

  $text = preg_replace ('/#site_name#/', $settings['site_name'], $text);
  $subject = preg_replace ('/#site_name#/', $settings['site_name'], $subject);
  $text = preg_replace ('/#site_url#/', $settings['site_url'], $text);
  $subject = preg_replace ('/#site_url#/', $settings['site_url'], $subject);
 ?> 
<table cellspacing=1 cellpadding=2 border=0 width=100%>
<tr>
 <td colspan=2><input type="checkbox" name="send_notification" value="1" checked onclick="chng_status()"> Send Notification?</td>
</tr>
<tr>
 <td>From: </td>
 <td><input type="text" name="from" value="<?php echo htmlspecialchars ($settings['admin_email']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>To: </td>
 <td>
 	<input type="text" name="to" value="<?php echo htmlspecialchars ($row['email']);?>" class=inpts size=50></td>
</tr>
<tr>
 <td>Subject: </td>
 <td><input type="text" name="subject" value="<?php echo htmlspecialchars ($subject);?>" class=inpts size=50></td>
</tr>
<tr>
  <td colspan=2>Message:</td>
</tr>
<tr>
  <td colspan=2>
  	<textarea name="text" cols=82 rows=5 class=inpts>
  		<?php echo htmlspecialchars ($text);?>
  	</textarea></td>
</tr>
<tr>
  <td colspan="2"><input style="width: 185px; height: 24px" type="submit" value="Approve & Save Changes" class=sbmt></td>
</tr>
</table>
</form>
